﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Minecraft.Data.NBT;

namespace Minecraft.Data {
    public class Mob : Entity {

        public short AttackTime;
        public short DeathTime;
        public short Health;
        public short HurtTime;
        public Boolean Saddle;
        public Boolean Sheared;
        public int Size;

        public Mob() : base() { }
        public Mob(Tag data)
            : base(data) {
            
            foreach (var child in data.Children) {
                switch (child.Name) {
            
                    case "AttackTime":
                        this.AttackTime = (short)child.Payload;
                        break;

                    case "DeathTime":
                        this.DeathTime = (short)child.Payload;
                        break;
                    
                    case "Health":
                        this.Health = (short)child.Payload;
                        break;
                    
                    case "HurtTime":
                        this.HurtTime = (short)child.Payload;
                        break;

                    case "Saddle":
                        this.Saddle = ((byte)child.Payload).Equals(1);
                        break;

                    case "Sheared":
                        this.Sheared = ((byte)child.Payload).Equals(1);
                        break;

                    case "Size":
                        this.Size = (int)child.Payload;
                        break;

                    default:
                        break;
                }
            }
        }

        new public Tag ToTag() {
            Tag root = base.ToTag();
            root.Name = "Mob";

            root.Children.Add(new Tag() { Type = TagType.Short, Name = "AttackTime", Payload = AttackTime });
            root.Children.Add(new Tag() { Type = TagType.Short, Name = "DeathTime", Payload = DeathTime });
            root.Children.Add(new Tag() { Type = TagType.Short, Name = "Health", Payload = Health });
            root.Children.Add(new Tag() { Type = TagType.Short, Name = "HurtTime", Payload = HurtTime });
            root.Children.Add(new Tag() { Type = TagType.Byte, Name = "Saddle", Payload = Convert.ToByte(Saddle) });
            root.Children.Add(new Tag() { Type = TagType.Byte, Name = "Sheared", Payload = Convert.ToByte(Sheared) });
            root.Children.Add(new Tag() { Type = TagType.Int, Name = "Size", Payload = Size });

            return root;
        }
    }
}
